package com.hunt.model.app;

import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.io.Serializable;
import java.util.List;
import java.util.UUID;


@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class FinancialSimpleDataInfo implements Serializable {

    private String id;

    private String ts_code;

    private String symbol;

    private String name;

    private String area;

    private String industry;

    private String list_date;

    private String totalShares;

    private String floatShares;

    private int isShutdown = 1;


    public FinancialSimpleDataInfo(JSONObject jsonObject, List<String> shutdownCodeList){
        JSONObject table = jsonObject.getJSONObject("table");
        String upperCode = table.getJSONArray("ths_thscode_stock").getString(0);
        if (shutdownCodeList.contains(upperCode)){
            this.isShutdown = 0;
        }
        this.id = UUID.randomUUID().toString().replaceAll("-","");
        this.ts_code = upperCode.toLowerCase();
        this.symbol = table.getJSONArray("ths_stock_code_stock").getString(0);
        this.name = table.getJSONArray("ths_stock_short_name_stock").getString(0);
        this.area = table.getJSONArray("ths_province_stock").getString(0);
        this.industry = table.getJSONArray("ths_the_sw_industry_stock").getString(0);
        this.list_date = table.getJSONArray("ths_ipo_date_stock").getString(0);
        this.totalShares = table.getJSONArray("ths_total_shares_stock").getString(0);
        this.floatShares = table.getJSONArray("ths_total_float_shares_stock").getString(0);
    }
}
